﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using DcsGauges.Server.Network;
using System.Reflection;
using DcsGauges.Server.Models;

namespace DcsGauges.Server.ViewModels
{
    class ClientsViewModel : ViewModelBase
    {
        private ServerModel                 serverModel                 = null;

        public ClientsViewModel(ServerModel serverModel)
        {
            this.serverModel                                = serverModel;
            this.serverModel.ServerModelChangedEvent        += OnServerModelServerModelChangedEvent;

            this.ConnectedClients                           = new ObservableCollection<IDcsGaugesClientChannel>(this.serverModel.DcsGaugesClients);
        }

        void OnServerModelServerModelChangedEvent(object sender, EventArgs e)
        {
            this.ConnectedClients           = new ObservableCollection<IDcsGaugesClientChannel>(this.serverModel.DcsGaugesClients);
        }

        private ObservableCollection<IDcsGaugesClientChannel> connectedClients = new ObservableCollection<IDcsGaugesClientChannel>();
        public ObservableCollection<IDcsGaugesClientChannel> ConnectedClients
        {
            get { return this.connectedClients; }
            set
            {
                if(this.connectedClients != value)
                {
                    this.connectedClients = value;
                    this.OnPropertyChanged(MethodBase.GetCurrentMethod());
                }
            }
        }
    }
}
